<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        li {
            list-style: none;
            float: left;
            width: 134px;
            height: 30px;
            line-height: 30px;
            text-align: center;
        }
        li.ac {
            background-color: #ccc;
        }
        img {
            width: 404px;
            height: 300px;
        }
        #box {
            width: 404px;
            margin: 0 auto;
        }
        ul {
            border: 1px solid #999;
            height: 30px;
        }
        .wrap div {
            display: none;
        }
        .wrap div.ac {
            display: block;
        }
    </style>
</head>
<body>
    <div id="box">
        <ul>
            <li class="ac">女枪</li>
            <li>阿狸</li>
            <li>阿卡丽</li>
        </ul>
        <div class="wrap">
            <div class="ac"><img src="../nvq.jpg" alt=""></div>
            <div><img src="../ali.jpg" alt=""></div>
            <div><img src="../akali.jpg" alt=""></div>
        </div>
    </div>
    <script>
        var btns = document.querySelectorAll('#box li')
        var imgs = document.querySelectorAll('#box .wrap div')

        // 循环绑事件事件里不能使用循环变量的，因为事件触发的时候循环变量早就加完了
        for(var i=0;i<btns.length;i++){
            
            btns[i].index = i;
            
            btns[i].onclick = function(e){
                var target = e.target || e.srcElement
                for(var j=0;j<btns.length;j++){
                    btns[j].classList.remove('ac')
                    imgs[j].classList.remove('ac')
                }
                target.classList.add('ac')
                // console.log(this.index)
                imgs[this.index].classList.add('ac')

            }
        }

    </script>
</body>
</html>